// 发送 Webhook 消息函数
import calculateSign from "./calculateSign";
import axios from "axios";

async function sendWebhookMessage(
    url: string,
    timestamp: string,
    message: string,
    secret: string
) {
    const sign = calculateSign(secret, timestamp);

    const data = {
        sign: sign,
        timestamp: timestamp,
        msgType: "text",
        msgData: {
            text: {
                content: message,
            },
        },
    };

    try {
        const response = await axios.post(url, data, {
            headers: {
                "Content-Type": "application/json",
            },
        });

        // console.log("消息发送成功：", response.data);
    } catch (error: any) {
        console.error("发送消息失败：", error.response?.data || error.message);
    }
}

export default sendWebhookMessage;